package writable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.net.URI;
public class Driver {
    public static void main(String[] args) throws Exception {
        // 获得job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        // 设置jar包
        job.setJarByClass(Driver.class);
        // 设置与mapper和reducer的关联
        job.setMapperClass(MapperTest.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        job.setReducerClass(ReduceTest.class);
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(FlowBean.class);

        // 关联文件的输入输出
        FileInputFormat.setInputPaths(job,new Path("hdfs://192.168.0.40:9000/phone_data.txt"));
          // 新路径
        Path outPath = new Path("hdfs://192.168.0.40:9000/phone1");
        FileSystem fs = FileSystem.get(new URI("hdfs://192.168.0.40:9000"),conf,"root");
        if(fs.exists(outPath)){
            fs.delete(outPath,true);
        }
        FileOutputFormat.setOutputPath(job,outPath);
        // 提交运行
        boolean result = job.waitForCompletion(true);
        System.exit(result?0:1);
    }
}
